
// <copyright file="KeyValuePairKeyEnumerable.cs" company="Subhadra Software Solutions">
//   
// </copyright>
// <summary>
//   The key value pair key enumerable.
// </summary>

namespace SubhadraSolutions.Sharp.Utils.Collections.Generic
{
    using System.Collections;
    using System.Collections.Generic;

    /// <summary>
    /// The key value pair key enumerable.
    /// </summary>
    /// <typeparam name="TKey">
    /// </typeparam>
    /// <typeparam name="TValue">
    /// </typeparam>
    public class KeyValuePairKeyEnumerable<TKey, TValue> : IEnumerable<TKey>
    {
        #region Fields

        /// <summary>
        /// The pairs.
        /// </summary>
        private readonly IEnumerable<KeyValuePair<TKey, TValue>> _pairs;

        #endregion Fields

        #region Constructors and Finalizers

        /// <summary>
        /// Initializes a new instance of the <see cref="KeyValuePairKeyEnumerable{TKey,TValue}"/> class.
        /// </summary>
        /// <param name="pairs">
        /// The pairs.
        /// </param>
        public KeyValuePairKeyEnumerable(IEnumerable<KeyValuePair<TKey, TValue>> pairs)
        {
            this._pairs = pairs;
        }

        #endregion Constructors and Finalizers

        #region Public Methods and Operators

        /// <summary>
        /// The get enumerator.
        /// </summary>
        /// <returns>
        /// The <see cref="IEnumerator"/>.
        /// </returns>
        public IEnumerator<TKey> GetEnumerator()
        {
            return new KeyValuePairKeyEnumerator(this._pairs.GetEnumerator());
        }

        #endregion Public Methods and Operators

        #region Explicit Interface Methods

        /// <summary>
        /// The get enumerator.
        /// </summary>
        /// <returns>
        /// The <see cref="IEnumerator"/>.
        /// </returns>
        IEnumerator IEnumerable.GetEnumerator()
        {
            return new KeyValuePairKeyEnumerator(this._pairs.GetEnumerator());
        }

        #endregion Explicit Interface Methods

        /// <summary>
        /// The key value pair key enumerator.
        /// </summary>
        private sealed class KeyValuePairKeyEnumerator : IEnumerator<TKey>
        {
            #region Fields

            /// <summary>
            /// The enumerator.
            /// </summary>
            private readonly IEnumerator<KeyValuePair<TKey, TValue>> _enumerator;

            #endregion Fields

            #region Constructors and Finalizers

            /// <summary>
            /// Initializes a new instance of the <see cref="KeyValuePairKeyEnumerator"/> class.
            /// </summary>
            /// <param name="enumerator">
            /// The enumerator.
            /// </param>
            public KeyValuePairKeyEnumerator(IEnumerator<KeyValuePair<TKey, TValue>> enumerator)
            {
                this._enumerator = enumerator;
            }

            #endregion Constructors and Finalizers

            #region Public Properties

            /// <summary>
            /// Gets the current.
            /// </summary>
            public TKey Current
            {
                get
                {
                    return this._enumerator.Current.Key;
                }
            }

            #endregion Public Properties

            #region Explicit Interface Properties

            /// <summary>
            /// Gets the current.
            /// </summary>
            object IEnumerator.Current
            {
                get
                {
                    return this._enumerator.Current.Key;
                }
            }

            #endregion Explicit Interface Properties

            #region Public Methods and Operators

            /// <summary>
            /// The dispose.
            /// </summary>
            public void Dispose()
            {
                this._enumerator.Dispose();
            }

            /// <summary>
            /// The move next.
            /// </summary>
            /// <returns>
            /// The <see cref="bool"/>.
            /// </returns>
            public bool MoveNext()
            {
                return this._enumerator.MoveNext();
            }

            /// <summary>
            /// The reset.
            /// </summary>
            public void Reset()
            {
                this._enumerator.Reset();
            }

            #endregion Public Methods and Operators
        }
    }
}
